# Python 2.6.4
# Project Euler, Problem 51
# Copyright 2010 Talha Zaman

import re
from mine import sieveprimes, isprime
primes = sieveprimes(1000000)
found = False
for p in primes:
    for digit in set(str(p)):
        length = len(str(p))
        test = [int(re.sub(str(digit), str(i), str(p))) for i in range(10)]
        test = [t for t in test if len(str(t))==length]
        if sum(isprime(t) for t in test) > 7:
            print [t for t in test if isprime(t)]
            found = True
            break
    if found: break
